<?php

/**
 * Yii Controller SiteController
 *
 * @author anhdung
 * @since 18-05-2013 - 15:20:32
 */
class SiteController extends MyController
{

    public function actions()
    {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xF7F3F3,
            ),
        );
    }

    public function actionIndex()
    {
        $this->render('index');
    }

    public function actionCategory()
    {
        $category = Category::model()->find(array(
            'condition' => 'url=' . "'" . $_GET['url'] . "'"
        ));
        $this->render('category', array(
            'category' => $category
        ));
    }

    public function actionDetails()
    {
        $product = Product::model()->find(array(
            'condition' => 'title_url=' . "'" . $_GET['url'] . "'"
        ));

        $this->render('details', array(
            'product' => $product,
        ));
    }

    public function actionContact()
    {
        $model = new Contact;
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'contact-form')
        {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }

        if (isset($_POST['Contact']))
        {
            $model->attributes = $_POST['Contact'];
            if ($model->validate())
            {
//                $model->language_id = $this->lang_id;
                $model->status = Contact::STATUS_NEW;
                $model->save();
                Yii::app()->user->setFlash('contact', Yii::t('contact', 'Thank you for contacting us. We will respond to you as soon as possible.'));
                $this->refresh();
            }
        }
        $this->render('contact', array('model' => $model));
    }

}

/** 
 * End file SiteController
 */
